<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title>登录</title>
    </head>
    <body>
        <form method="post" action="<?php echo $_SERVER["PHP_SELF"] ?>">
            用户名：<input type="text" name="user">
            <br><br>
            密码：<input type="password" name="pwd">
            <br><br>
            <input type="submit" name="submit" value="登录">
            <input type="button" value="返回" onclick="window.location.href = 'index.php'">
        </form>
        <?php
        require 'lyb_conn.php';
        if (isset($_POST['submit'])) {
            $sql = "select * from n2 where user='$_POST[user]'";
            $res = mysqli_query($con, $sql);
            $res= mysqli_fetch_array($res);
            if (password_verify($_POST[pwd], $res[pwd])) {
                session_start();
                $_SESSION['user']=$_POST[user];
                echo "<script type='text/javascript'>window.location.href='index.php'</script>";
            } else {
                echo "<script type='text/javascript'>alert('用户名或密码错误，请重新输入！')</script>";
            }
        }
        ?>
    </body>
</html>
